package com.soft.javase.day06.string;

import java.util.Scanner;

/**
 * @author yzg
 * @desc TODO
 * @date 2025/4/24
 */
public class StringDemo3 {
    public static void main(String[] args) {
        System.out.println("----用StringBuilder把数组拼接成一个字符串----");
        int[] arr = {1, 2, 3};

        StringBuilder sb = new StringBuilder();
        sb.append("[");

        for (int i = 0; i < arr.length; i++) {
            sb.append(arr[i]);
            if (i < arr.length - 1) {
                sb.append(", ");
            }
        }

        sb.append("]");
        System.out.println(sb);

        System.out.println();
        System.out.println("----利用StringBuilder完成字符串反转----");
        StringBuilder sb1 = new StringBuilder("hello world");
        System.out.println(sb1.reverse());

        System.out.println();
        System.out.println("----判断一个字符串是否是对称字符串----");
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个字符串：");
        String str = sc.nextLine();
        if(new StringBuilder(str).reverse().toString().equals(str)){
            System.out.println("该字符串是对称字符串");
        }else {
            System.out.println("该字符串不是对称字符串");
        }
    }
}
